#!/usr/bin/python
#coding:utf8
'''
Iterator
'''
class ComputeNumber:
    def __init__(self,n):
        self.n = n
        self.index = 0
    
    def __iter__(self):
        return self

    def __next__(self):
        if self.index < self.n:
            value = self.index**2
            self.index += 1
            return value
        else:
            raise StopIteration()

if __name__ == '__main__':
    print("逐个遍历:")
    x = ComputeNumber(10)
    for i in range(4):
        print(next(x),end=',')
    print("\nfor循环遍历：")
    for s in x:
        print(s,end=',')